<?php

namespace app\admin\controller;


use app\common\model\ShopMember;
use app\common\service\Status;
use app\common\model\ShopMemberLevel;
use buildView\Button;
use buildView\Detail;
use buildView\Filter;
use think\Controller;
use buildView\Form;
use buildView\Grid;
use app\common\model\User;

/**
 * 会员等级
 * Class MemberLevel
 * @package app\admin\controller
 */
class MemberLevel extends Controller
{
    /**
     * 列表
     * @auth true
     * @menu true
     * @return string
     */
    public function index()
    {
        $grid = new Grid(new ShopMemberLevel());
        $grid->level_name('等级名称');
        $grid->discount('折扣(0.8是八折，禁止大于1)');
        $grid->create_at('创建时间');
        $grid->setFromOpen();
        // $grid->hideAddButton();
        $grid->hideDeletesButton();
        $grid->hideExportButton();
        $grid->filter(function(Filter $filter){
           $filter->like('level_name','等级名称');
           $filter->eq('discount','折扣');
           $filter->dateBetween('create_at','注册时间');
        });
        $grid->actions(function($action,$data){
            $action->hideDel();
            // $action->hideEdit();
            // $button = new Button('会员卡信息');
            // $button->href(url('memberInfo') . "?id={$data['id']}", 'modal');
            // $action->append($button);
            // $button2 = new Button('钱包明细','normal');
            // $button2->href(url('money_record/index') . "?id={$data['id']}");
            // $action->append($button2);
        });
        return $grid->view();
    }

    /**
     * 添加/编辑
     * @auth true
     * @menu true
     * @return string
     */
    public function form()
    {
        $form = new Form(new ShopMemberLevel);
		$form->text('level_name','等级名称')->required();
		$form->text('discount','折扣')->required();
        $form->saved(function($post,$model){
            (new ShopMemberLevel)->saveAll($post);
            return $post;
        });
        return $form->view();
    }

    /**
     * 详情
     * @auth true
     * @menu true
     * @return string
     */
    public function detail()
    {
        $detail = new Detail(new ShopMemberLevel);
        $detail->setTitle('会员等级信息');
        $detail->layout('基本信息', 12, function ($detail) {
            $detail->level_name('等级名称');
            $detail->discount('折扣');
        });
        return $detail->view();
    }
    
}
